import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home/index.vue'
import Types from '../views/Types'
import Video from '@/views/Video'
import My from '@/views/My' 
import Myindex from '@/views/My/myindex' 
import Login from '@/views/My/login' 
import Register from '@/views/My/register'
import Cart from '@/views/Cart'
import store from '@/store/index'
import Address from '@/views/Address'
// import { component } from 'vue/types/umd'
// import { AddressEdit } from 'vant'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'home',
    component: Home
  },
  {
    path: '/types',
    component: Types
  },
  {
    path: '/videos',
    component: Video
  },
  {
    path:'/cart',
    component: Cart
  },
  { path: '/my', // 父路径 
      component: My, // 父页面 
      children: [ // 所有子路径和页面 
      { 
        path: '/', // 子路径 
        component: Myindex, // 子页面 
      },
      { path: 'login', // 子路径 
      component: Login // 子页面 
      },
      { path: 'register', // 子路径 
      component: Register // 子页面 
      } 
    ] 
  },
  {
    path :'/address',
    component : Address
  }
]

const router = new VueRouter({
  routes
})

router.afterEach((to,from) => {
  var active
  if(to.path.startsWith('/my')){
    active = 4
  } else { 
    active = routes.findIndex(item => item.path === to.path) 
  }
  // if(to.path === '/'){
  //   active = 0
  // }else if(to.path === '/types'){
  //   active = 1
  // }else if(to.path === '/videos'){
  //   active = 2
  // }else if(to.path === '/cart'){
  //   active = 3
  // }
  store.commit('changeActive',active)
})

export default router
